{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 1161/1161 [00:02<00:00, 486.68it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mean =  [0.15590965 0.15591361 0.15588932]\n",
      "std =  [0.10875295 0.10875973 0.10869502]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "import cv2, os, argparse\n",
    "import numpy as np\n",
    "from tqdm import tqdm\n",
    "\n",
    "\n",
    "def main():\n",
    "    \n",
    "    dirs = '../datasets/SSDD/JPEGImages'  # 修改你自己的图片路径\n",
    "    img_file_names = os.listdir(dirs)\n",
    "    \n",
    "    m_list, s_list = [], []\n",
    "    for img_filename in tqdm(img_file_names):\n",
    "#         print(\"img_filename\",img_filename)\n",
    "        try:\n",
    "            img = cv2.imread(dirs + '/' + img_filename)\n",
    "            img = img / 255.0\n",
    "            m, s = cv2.meanStdDev(img)\n",
    "            m_list.append(m.reshape((3,)))\n",
    "            s_list.append(s.reshape((3,)))\n",
    "        except:\n",
    "            pass\n",
    "    m_array = np.array(m_list)\n",
    "    s_array = np.array(s_list)\n",
    "    m = m_array.mean(axis=0, keepdims=True)\n",
    "    s = s_array.mean(axis=0, keepdims=True)\n",
    "    print(\"mean = \", m[0][::-1])\n",
    "    print(\"std = \", s[0][::-1])\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    main()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
